package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zr.model.UserModel;
import com.zr.service.MangerSelectService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 更新信息信息
 * @author xl
 *
 */
public class GetStMangerUpdateController extends HttpServlet{
	MangerSelectService sss=new MangerSelectService();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		boolean flag=false;
		req.setCharacterEncoding("utf8");
		String stus = req.getParameter("students");
		JSONArray jArray=JSONArray.fromObject(stus);
		List<UserModel> userlist=new ArrayList<>();
		for(int i=0;i<jArray.size();i++){
			JSONObject jObject=jArray.getJSONObject(i);
			UserModel uModel=new UserModel();
			uModel.setSid(jObject.getInt("sid"));
			uModel.setSname(jObject.getString("sname"));
			uModel.setScollege(jObject.getString("scollege"));
			uModel.setSsex(jObject.getString("ssex"));
			uModel.setSage(jObject.getInt("sage"));
			uModel.setSaddress(jObject.getString("saddress"));
			uModel.setSphone(jObject.getString("sphone"));
			userlist.add(uModel);
		}
		flag=sss.getStudentUpdate(userlist);
		//发送修改结果
		resp.setCharacterEncoding("utf8");
		PrintWriter pw=resp.getWriter();
		if(flag){
			pw.write("修改成功");
		}
	}
}
